<?php
class ecTemplate{

  public $title = '';
  public $metaTagsArray = array();
  public $metaTagsHtml = '';
  public $metaTagsHttpEquivArray = array();
  public $metaTagsHttpEquivHtml = '';
  public $linksArray = array();
  public $linksHtml = '';

  public function setTitle($title)
  {
    if(isset($title))
      $this->title = $title;
  }

  public function getTitle()
  {
    if(strlen($this->title) > 0)
      return "<title>".$this->title."</title>\n\r";
  }

  public function setMetaTags($arrayContent = array())
  {
    $this->metaTagsArray = array_merge($this->metaTagsArray, $arrayContent);
    $this->metaTagsHtml = '';

    if(sizeof($this->metaTagsArray) > 0)
    {
      foreach ($this->metaTagsArray as $name => $content)
      {
        $this->metaTagsHtml .= '<meta name="'.$name.'" content="'.$content.'" />'."\n\r";
      }
    }
  }

  public function setMetaTagsHttpEquiv($arrayContent = array())
  {
    $this->metaTagsHttpEquivArray = array_merge($this->metaTagsHttpEquivArray, $arrayContent);
    $this->metaTagsHttpEquivHtml = '';

    if(sizeof($this->metaTagsHttpEquivArray) > 0)
    {
      foreach ($this->metaTagsHttpEquivArray as $name => $content)
      {
        $this->metaTagsHttpEquivHtml .= '<meta http-equiv="'.$name.'" content="'.$content.'" />'."\n\r";
      }
    }
  }

  public function setLinks($arrayParams = array())
  {
    $this->linksArray = array_merge($this->linksArray, $arrayParams);
    $this->linksHtml = '';
    
    if(sizeof($this->linksArray) > 0)
    {
      foreach($this->linksArray as $arrayParam)
      {
        $this->linksHtml .= '<link';

        foreach($arrayParam as $key => $value)
        {
          $this->linksHtml .= ' '.$key.'="'.$value.'"';
        }
        $this->linksHtml .= ' />'."\n\r";
      }
    }
  }

  public function getLinksArray()
  {
    return $this->linksArray;
  }

  public function getLinksHtml()
  {
    return $this->linksHtml;
  }

  public function getMetaTagsHtml()
  {
    return $this->metaTagsHtml;
  }

  public function getMetaTagsArray()
  {
    return $this->metaTagsArray;
  }

  public function getMetaTagsHttpEquivHtml()
  {
    return $this->metaTagsHttpEquivHtml;
  }

  public function getMetaTagsHttpEquivArray()
  {
    return $this->metaTagsHttpEquivArray;
  }

  public function setTemplateAction($template)
  {
    if(!$this->params['templateAction'] = $template.'.tpl.php')
      return false;
    return true;
  }

  public function loadTemplate($template)
  {
    global $debug;
    $this->setTemplateAction($template);

    if($this->params['layout'] == true)
    {
      if(secure::includeVerif(dirname(__FILE__).'/../../../apps/'.$this->params['applicationName'].'/views/'.$this->params['templateLayout']))
        if(array_key_exists('templateLayout', $this->params))
          require(dirname(__FILE__).'/../../../apps/'.$this->params['applicationName'].'/views/'.$this->params['templateLayout']);
        else
          throw new Exception ('templateLayout Param not exist ');
    }
    else
    {
      if(secure::includeVerif(dirname(__FILE__).'/../../../apps/'.$this->params['applicationName'].'/modules/'.$this->params['moduleName'].'/views/'.$this->params['templateAction']))
        if(array_key_exists('templateAction', $this->params))
          require(dirname(__FILE__).'/../../../apps/'.$this->params['applicationName'].'/modules/'.$this->params['moduleName'].'/views/'.$this->params['templateAction']);
        else
          throw new Exception ('templateAction Param not exist ');
    }

    if(ecEnvironment::isDebug())
    {
        echo bl_debug();
    }
  }
}

?>
